<?php

namespace app\api\controller;
use app\common\utils\aliyun\Sms;
use app\common\utils\Is;

class VerificationCodeController
{
    protected $noNeedLogin = ['send'];
    
    public function send()
    {
        $mobile = request()->post('mobile', '');
        if (!Is::mobile($mobile)) {
            return apiError('请输入正确的手机格式!');
        }
        $code = Sms::getVerificationCode($mobile);
        if (empty($code)) {
            return apiError("验证码发送过多,请明天再试!");
        }
        $result = Sms::send($mobile, $code);
        if (empty($result['code'])) {
            return apiError($result['msg']);
        }
        return apiSuccess('验证码已经发送成功!');
    }
    
}